<?php
	include_once("model/HistoriaService.php");
	include_once("model/utils/Fechas.php");
	
	$service = new HistoriaService();
	$fechas = new Fechas();
	
	$historias = $service->getByProyecto($_SESSION["idProyecto"]);
?>
<div id="backlog" class="contenedorGris minHeight">
	<div class="floatFix">
		<h3 class="floatLeft">HISTORIAS</h3>
		<?php if($_SESSION["rol"] == 1 || $_SESSION["rol"] == 2){ ?>
		<a href="<?php echo URL_BASE(); ?>/view/components/editHistoria.php?id_usuario=<?php echo $_SESSION["id_usuario"]; ?>" class="crear floatRight">Crear Historia</a>
		<?php } ?>
	</div>
	<?php foreach($historias as $hist){ ?>
	<div class="historia" id="historia<?php echo $hist->id; ?>">
		<a href="" class="titulo">
			<img alt="" src="<?php echo URL_BASE(); ?>/view/images/bullet-historia.png" class="bullet-historia" />
			<?php echo $hist->titulo; ?>
			<img alt="" src="<?php echo URL_BASE(); ?>/view/images/arrow-down.png" class="arrow" />
		</a>
		<?php if($_SESSION["rol"] == 1 || $_SESSION["rol"] == 2){ ?>
		<a href="<?php echo URL_BASE(); ?>/view/components/editHistoria.php?id_usuario=<?php echo $_SESSION["id_usuario"]; ?>&id_historia=<?php echo $hist->id; ?>" class="crear editar">Editar</a>
		<?php } ?>
		<div class="descripcion">
			<p><span>DESCRIPCI&Oacute;N:</span> <?php echo $hist->descripcion; ?></p>
			<p><span>OBJETIVOS:</span> <?php echo $hist->objetivos; ?></p>
			<br />
			<div class="tareas">
				<table cellpadding="0" cellspacing="0" border="0" width="100%">
					<thead>
						<td width="25%">Tareas</td>
						<td width="15%">Estado</td>
						<td width="20%">Asignada</td>
						<td width="13%">Deadline</td>
						<td width="14%" align="center">Configurar</td>
						<td width="13%" align="center">
						<?php if($_SESSION["rol"] == 1 || $_SESSION["rol"] == 2){ ?>
						<a href="<?php echo URL_BASE(); ?>/view/components/editTarea.php?id_usuario=<?php echo $_SESSION["id_usuario"]; ?>&id_historia=<?php echo $hist->id; ?>" class="crear">Crear Tarea</a>
						<?php } ?>
						</td>
					</thead>
					<tbody>
					<?php foreach($hist->tareas as $tarea){ ?>
						<tr height="30" valign="middle" id="tarea<?php echo $tarea->id; ?>">
							<td class="titulo"><?php echo $tarea->titulo; ?></td>
							<td class="estado"><?php echo $tarea->estado; ?></td>
							<td class="usuario"><?php echo $tarea->usuario; ?></td>
							<td class="deadline"><?php echo $fechas->convertirFecha($tarea->deadline); ?></td>
							<td align="center" class="editar">
							<?php 
								if($tarea->id_estado != 3){ 
									if($_SESSION["rol"] == 1 || $_SESSION["rol"] == 2){ 
							?>
								<a href="<?php echo URL_BASE(); ?>/view/components/editTarea.php?id_usuario=<?php echo $_SESSION["id_usuario"]; ?>&id_historia=<?php echo $hist->id; ?>&id_tarea=<?php echo $tarea->id; ?>" class="crear" title="Editar"><img alt="Editar" src="<?php echo URL_BASE(); ?>/view/images/editar.png" /></a>
							<?php }
									if($_SESSION["rol"] == 1 || $_SESSION["rol"] == 2 || $tarea->id_usuario == $_SESSION["id_usuario"]){
							?>
								<a href="<?php echo $tarea->id; ?>" title="Finalizar" class="finalizar"><img alt="Finalizar" src="<?php echo URL_BASE(); ?>/view/images/finalizar.png" /></a>
							<?php } 
									if($_SESSION["rol"] == 1 || $_SESSION["rol"] == 2){
							?>
								<a href="<?php echo $tarea->id; ?>" title="Eliminar" class="eliminar"><img alt="Eliminar" src="<?php echo URL_BASE(); ?>/view/images/tachito.png" /></a>
							<?php 	}
								}else{ ?>
								Finalizada
							<?php } ?>
							</td>
							<td align="center"></td>
						</tr>
					<?php } ?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<?php } ?>
</div>